home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.lang.c++,gnu.gcc.help,gnu.g++.help,comp.os.msdos.djgpp
- Path: cwi.nl!dik
- From: dik@cwi.nl (Dik T. Winter)
- Subject: Re: float != float and floats as return types
- Message-ID: <DM04ur.I6u@cwi.nl>
- Sender: news@cwi.nl (The Daily Dross)
- Nntp-Posting-Host: chrysant.cwi.nl
- Organization: CWI, Amsterdam
- References: <4ej9lb$mpc@fu-berlin.de>
- Date: Tue, 30 Jan 1996 16:08:50 GMT
-
- In article <4ej9lb$mpc@fu-berlin.de> axl@zedat.fu-berlin.de writes:
- > Hello,
- > I am getting confused, about how C/C++ manage float binary operations,
- > in particular multiplication. The next C++ example gives me surprising
- > results:
- ...
- > float quad( float );
- ...
- > a = i/13.123123;
- > b = a*a;
- > c = quad(a);
- > cout << (b - c) << '\t';
- > cout << (b - a*a) << '\t';
- > cout << (c - quad(a)) << '\n';
-
- Declaring a function as returning float does not imply that the actual
- value returned is indeed a float! In K&R times expressions involving
- floats were calculated using doubles. Some compilers extended that
- to functions declared as returning float: a double result was returned;
- others did indeed truncate the return value to float. Thorough
- reading of K&R does not lead to a clear solution here. In ANSI C both
- are allowed.
- --
- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924098
- home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
-